home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- # fup - file update script
- # copyright (c) 2000, joseph cheek, joseph@redmondlinux.org
- # released under gpl.
- #
- # $1: full pathname of updated file
- # $2: directory [inside buildroot] to place file
- # ex: fup /home/joseph/myfile col/devel
- #
- # opts: -q: quiet [don't print status messages]
- # -f: force [update even when older]
- # -l: language to add to [default: all languages]
-
- # BUG: use getopts instead
- LANG=
-
- if [ "n$1" = "n-q" ]; then # -q
- QUIET="-q"
- shift
- fi
-
- if [ "n$1" = "n-f" ]; then # -f
- FORCE="(force)"
- shift
- fi
-
- if [ "n$1" = "n-l" ]; then # -l
- LANG="$2"
- shift
- shift
- fi
-
- if [ ! -r "$1" ]; then # file doesn't exist
- ( echo `basename $0`: can\'t find \"$1\"
- echo
- echo usage: `basename $0` \[-q\] \[-f\] \[-l lang\] file dir
- echo updates file in dir of redmond linux build system
- echo -q is quiet, ie don\'t print status messages
- echo -f is force, ie update even if updated file is older
- echo -l is language or all if not present ) >&2
- exit 1
- fi
-
- if [ $# -lt 2 ]; then # no dir given
- ( echo `basename $0`: no dir given
- echo perhaps you wanted pup?
- echo
- echo usage: `basename $0` \[-q\] \[-f\] \[-l lang\] file dir
- echo updates file in dir of redmond linux build system
- echo -q is quiet, ie don\'t print status messages
- echo -f is force, ie update even if updated file is older
- echo -l is language or all if not present ) >&2
- exit 1
- fi
-
- # constants and vars
-
- RL_ROOT=/opt/redmondlinux
- BUILD_NUM_FILE=$RL_ROOT/builds/CURRENT_BUILD
- BUILD_NUM=`cat $BUILD_NUM_FILE`
- BUILD_ROOT=$RL_ROOT/builds/$BUILD_NUM
-
- BASENAME=`basename "$1"`
-
- cd $BUILD_ROOT
- LANG_TO_PROCESS=`echo ${LANG}*`
- cd -
-
- for lang in $LANG_TO_PROCESS; do
-
- CHANGELOG=$BUILD_ROOT/$lang/CHANGELOG
- UPDATED_FILE="$BUILD_ROOT/$lang/$2/$BASENAME"
-
-
- # more error checks
-
- if [ ! -d $BUILD_ROOT/$lang/"$2" ]; then # dir doesn't exist
- ( echo `basename $0`: can\'t find \"$BUILD_ROOT/$lang/$2\"
- echo
- echo usage: `basename $0` \[-q\] \[-f\] \[-l lang\] file dir
- echo updates file in dir of redmond linux build system
- echo -q is quiet, ie don\'t print status messages
- echo -f is force, ie update even if updated file is older
- echo -l is language or all if not present ) >&2
- exit 1
- fi
-
- if [ ! -f "$UPDATED_FILE" ]; then # updated file doesn't exist
- ( echo `basename $0`: can\'t find \"$UPDATED_FILE\"
- echo perhaps you need to add it, not update it ) >&2
- exit 1
- fi
-
- if [ ! "$1" -nt "$UPDATED_FILE" -a -z "$FORCE" ]; then # timestamps say it's not newer
- ( echo `basename $0`: "$1" isn\'t newer than $UPDATED_FILE
- echo use -f to force updating ) >&2
- exit 1
- fi
-
- #
- #
- # get data of file to be replaced
-
- # uid, gid
-
- _UID=`ls -l "$UPDATED_FILE" | tr -s \ | cut -d \ -f 3`
- _GID=`ls -l "$UPDATED_FILE" | tr -s \ | cut -d \ -f 4`
-
-
- #
- #
- # perform the update
-
- # copy the file
-
- cp -f "$1" "$UPDATED_FILE"
- if [ "$?" -gt 0 ]; then # file copy failed
- ( echo `basename $0`: copy failed
- echo perhaps you need to add it, not update it ) >&2
- exit 1
- fi
-
- # chown
-
- chown $_UID.$_GID "$UPDATED_FILE"
- if [ "$?" -gt 0 ]; then # chown failed
- ( echo `basename $0`: chown failed
- echo not a fatal error, but check ownership of "$UPDATED_FILE" ) >&2
- fi
-
- # update changelog
-
- echo u "$2/$BASENAME" "$FORCE" >> $CHANGELOG
-
- if [ "$?" -gt 0 ]; then # update changelog failed
- ( echo `basename $0`: update changelog failed
- echo check permissions on $CHANGELOG ) >&2
- exit 1
- fi
-
-
- tail -n 1 $CHANGELOG
-
- done
-
- exit 0
-